package com.zzyl.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> getByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);

        Page<NursingProject> page=nursingProjectMapper.getByPage(name,status);
        //log.info("分页查询的数据：{}",page.toString());
        PageResponse<NursingProjectVo> nursingProjectVo = PageResponse.of(page, NursingProjectVo.class);
        return nursingProjectVo;
    }

    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {
        if (nursingProjectDto != null){
            NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
            nursingProjectMapper.addNursingProject(nursingProject);
        }
    }

    @Override
    public NursingProjectVo getById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.getById(id);
        NursingProjectVo nursingProjectVo = BeanUtil.toBean(nursingProject, NursingProjectVo.class);
        return nursingProjectVo;
    }

    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

    @Override
    public void updateStatus(Long id, Integer status) {
        nursingProjectMapper.updateStatus(id,status);
    }

    @Override
    public void deleteById(Long id) {
        nursingProjectMapper.deleteById(id);
    }

    @Override
    public List<NursingProjectVo> getAll() {

        List<NursingProject> nursingProject = nursingProjectMapper.getAll();
        List<NursingProjectVo> nursingProjectVo = BeanUtil.copyToList(nursingProject, NursingProjectVo.class);
        return nursingProjectVo;
    }


}
